<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.min.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/md5.js"></script>

</head>

<body>
    <style>
        html,
        body {
            height: 100%;
        }
        .aui-list {
            background: none;
        }

        .aui-list li {
            background: #fff;
        }
    </style>
    <div id="cover">
        <div id="cover_left"></div>
        <div id="cover_right"></div>
        <div id="cover_foot"></div>
        <div id="cover_top"></div>
        <div class="login-t-1">市管领导干部信息查询系统</div>
        <div class="login-t-2">中共佳木斯市委组织部</div>
    </div>
    <!-- 登录 -->
    <div class="aui-content login">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label-icon">
                        <i class="aui-iconfont aui-icon-my"></i>
                    </div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="账号" name='name'>
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label-icon">
                        <i class="aui-iconfont aui-icon-lock"></i>
                    </div>
                    <div class="aui-list-item-input">
                        <input type="password" placeholder="密码" name='password'>
                    </div>
                    <!-- <div class="aui-list-item-label-icon">
                    <i class="aui-iconfont aui-icon-display"></i>
                </div> -->
                </div>
            </li>
        </ul>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="login()">登录</div>

    </div>
</body>
<script type="text/javascript" src="./script/api.js"></script>

</html>

<script>
    function login() {
      api.openWin({
          name: 'index',
          url: './index.html',
      });
      return;

        var loginName = $('input[name="name"]').val();
        var password = $('input[name="password"]').val();
        // loginName = 'szk01';
        // password='123'
        loginName = "'" + loginName + "'";
        var j = $.md5(password);
        j = j.toUpperCase();
        var sql = "SELECT * FROM SYsuserList WHERE ugrade ='查询' AND LoginName= " + loginName;
        // alert(sql);
        var db = api.require('db');
        db.selectSql({
            name: 'data',
            sql: sql
        }, function(ret, err) {
            if (ret.status) {
              // alert(JSON.stringify(ret));
              if (!ret.data.length) {
                api.toast({
                    msg: '用户名或密码错误',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
              }
                if (ret.data[0].Password == j) {
                  api.openWin({
                      name: 'index',
                      url: './index.html',
                  });
                } else {
                    api.toast({
                        msg: '用户名或密码错误',
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            } else {
                // alert(JSON.stringify(err));
            }
        });

        // var temp = $api.getStorage('user');
        // var tempassWord = $api.getStorage('passWord');
        // // alert(tempassWord);return;
        // var name = $('input[name="name"]').val();
        // var password = $('input[name="password"]').val();
        // var a = $.inArray(name, temp);
        // var b = $.inArray(password, tempassWord);
        // if (a != -1 && b != -1 &&a==b) {
        //
        //     $api.setStorage('currentPassword', b);
        //
        //     api.openWin({
        //         name: 'index',
        //         url: './index.html',
        //     });
        // } else {
        //     api.toast({
        //         msg: '用户名或密码不正确！',
        //         duration: 2000,
        //         location: 'middle'
        //     });
        // }

    }

    apiready = function() {
      api.setScreenOrientation({
          orientation: 'auto'
      });

        //index 刷新用
        $api.setStorage('tabIndex', null);
        api.addEventListener({
                name: 'keyback'
            }, function(ret, err) {
                api.closeWidget();
            })
            // is_wifi();
    }

    function is_wifi() {

        var wifissid = api.require('wifiSSID');
        wifissid.getSsid(null, function(ret, err) {
            if (ret.ssid && ret.ssid != '0x') {
                alert('请关闭wifi!');
                api.closeWidget({
                    id: 'A6076154446731',
                    retData: {
                        name: 'closeWidget'
                    },
                    silent: true,
                    animation: {
                        type: 'flip',
                        subType: 'from_bottom',
                        duration: 500
                    }
                });
            } else {}
        });


        api.addEventListener({
            name: 'online'
        }, function(ret, err) {
            alert('请关闭wifi!');
            api.closeWidget({
                id: 'A6076154446731',
                retData: {
                    name: 'closeWidget'
                },
                silent: true,
                animation: {
                    type: 'flip',
                    subType: 'from_bottom',
                    duration: 500
                }
            });
        });
    }
</script>
